import { curry } from './utility';

export type TypeCheckFunction = (type: string, target: any) => boolean;

export interface Inspectors {
    [key: string]: TypeCheckFunction;
}

/**
 * 类型判断函数
 * @author Wang LiZhi
 * @param { sting } type 要判断的类型
 * @param { any } target 需要进行类型判断的目标对象
 * @returns { boolean } 返回类型判断结果
 */
function isType(type: string, target: any): boolean {
  return Object.prototype.toString.call(target) === `[object ${type}]`;
}

const curryingType = curry(isType);


const isString = curryingType('String');
const isNumber = curryingType('Number');
const isBoolean = curryingType('Boolean');
const isNull = curryingType('Null');
const isUndefined = curryingType('Undefined');
const isSymbol = curryingType('Symbol');
const isBigInt = curryingType('BigInt');
const isArray  = curryingType('Array');
const isObject = curryingType('Object');
const isFunction = curryingType('Function');
const isAsyncFunction = curryingType('AsyncFunction');
const isDate = curryingType('Date');
const isRegExp = curryingType('RegExp');
const isSet = curryingType('Set');
const isMap = curryingType('Map');
const isWeakSet = curryingType('WeakSet');
const isWeakMap = curryingType('WeakMap');
const isPromise = curryingType('Promise');

export {
  isType,
  isString,
  isNumber,
  isBoolean,
  isNull,
  isUndefined,
  isSymbol,
  isBigInt,
  isArray ,
  isObject,
  isFunction,
  isAsyncFunction,
  isDate,
  isRegExp,
  isSet,
  isMap,
  isWeakSet,
  isWeakMap,
  isPromise,
};
